#include"TcpServer.hpp"
#include"Http.hpp"
#include"Deamon.hpp"

HttpResponse Login(HttpRequest &req)
{
    HttpResponse resp;
    std::string s=req.GetRequestBody();
    resp.AddCode(200,"success");
    resp.AddBodyText("<html><h1>get!</h1></html>");
    std::cout<<"get target done!"<<std::endl;
    std::cout<<"--------------------------"<<std::endl;
    return resp;
}

int main(int argc,char *argv[])
{
    if(argc!=2)
    {
        std::cerr<<"Usage:"<<argv[0]<<" serverport"<<std::endl;
    }
    uint16_t port=std::stoi(argv[1]);
    Deamon(false,false);
    HttpServer hserver;
    hserver.InsertService("/login",Login);

    std::unique_ptr<TcpServer> tsvr=std::make_unique<TcpServer>(std::bind(&HttpServer::HandlerHttpRequest,&hserver,std::placeholders::_1),port);
    tsvr->Loop();
    return 0;
}